﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using WebRole1;

/// <summary>
/// Summary description for tweet
/// </summary>
public class tweet
{
	public tweet()
	{}

    private readonly oAuthTwitter _oAuth = new oAuthTwitter();

    public bool sendTweet(string msg)
    {
        _oAuth.Token = ConfigurationManager.AppSettings["token"];
        _oAuth.TokenSecret = ConfigurationManager.AppSettings["tokensecret"];
        _oAuth.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
        _oAuth.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
        if (msg.Length == 0)
        {
            //Response.Write("Your tweet must be at least 1 character long!");
            return false;
        }
        try
        {
            // URL-encode the tweet...
            string tweet = HttpUtility.UrlEncode(msg);

            // And send it...
            string xml = _oAuth.oAuthWebRequest(
            oAuthTwitter.Method.POST,
            "http://twitter.com/statuses/update.xml",
            "status=" + tweet);

            return true;
        }
        catch (Exception ex)
        {
            //Response.Write("An error occurred while posting your tweet:\n\n" + ex.Message);
            return false;
        }
        //txtTweet.Text = String.Empty;
    }
}